﻿using System;
using System.Collections;
using System.Collections.Generic;
using HR60_PanelSoft.Model;
using HR60_PanelSoft.View.Base;
using System.ComponentModel;
using System.Windows.Forms;

namespace HR60_PanelSoft.View.TabForms.ListItems
{
    //GC: [g1]优化：将核心的基础控件传递到外层[ButtonItemScene]
	public partial class ButtonItemScene : BaseFormControl
	{
		public ButtonItemScene()
		{
			InitializeComponent();

			//selScene.ValueChanged += new EventHandler(valueChange);
            selScene.ValueChanged += new ValueChangedHandler(valueChange);
		}

		[Browsable(true)]
		[Description("标题"), Category("String"), DefaultValue("标题")]
		public string Title
		{
			get
			{
				return ltlId.Text;
			}
			set
			{
				ltlId.Text = value;
			}
		}

		/// <summary>
		/// 绑定按钮数据
		/// </summary>
		/// <param name="btn"></param>
		public void bindButton(PanelButton btn)
		{
			this.CatchValueChange = false;
			selScene.CatchValueChange = false;
			
			// 不选择按钮状态
			if (btn == null)
			{
				selScene.cleanItems();
				ltlId.Text = "未选择";
				this.Enabled = false;
				return;
			}
			
			// 查找已关联的场景
			Scene scene = findSceneByUuid(btn.mappingScene);

			// 场景
			selScene.setStaticFirstItem("选择场景");
			selScene.bindData((IList) scenes, "name");
			if (scene != null) selScene.Value = scene;

			this.Enabled = true;
			this.CatchValueChange = true;
			selScene.CatchValueChange = true;
		}

		// 重写Value属性
		public override object Value
		{
			get
			{
				return selScene.Value;
			}
			set
			{
				selScene.Value = value;
			}
		}

        /* [g1.s1] */

        public override List<Control> GetCoreControls()
        {
            List<Control> rst = new List<Control>();
            rst.Clear();

            rst.Add(selScene);

            return rst;
        }

        /* end of [g1.s1] */
	}
}
